package com.scoressystem.controller;


import com.scoressystem.pojo.Student;
import com.scoressystem.service.ScoresService;
import com.scoressystem.service.StudentService;
import com.scoressystem.utils.Results;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    @Resource
    private StudentService studentService;
    @Resource
    private ScoresService scoresService;


    @RequestMapping("/getStudScores")
    public Results<Map<String, List<Object>>> getStudScores() {
        List<Student> allStudentsBySname = studentService.getAllStudentsBySname("");
        List<Object> studentNames = new ArrayList<>();
        List<Object> scoresList = new ArrayList<>();

        Map<String, List<Object>> stuScores = new HashMap<>();

        for (Student student : allStudentsBySname) {
            studentNames.add(student.getStudentName());
            Double scores = scoresService.getScoresByStuId(student.getStudentNo());
            scoresList.add(scores);
        }
        stuScores.put("stuNames", studentNames);
        stuScores.put("stuScores", scoresList);
        return new Results<>("0", "查询成功", stuScores);
    }

}
